﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Xml.Linq;
using WinForms = System.Windows.Forms;

using SilverMap;

namespace WpfSilverMap {
	/// <summary>
	/// Overload the MapControl class to customise the user interface.
	/// </summary>
	public class MapControl: SilverMap.MapControl {
		public override void AddTools() {
			page.AddTool( "load", "Load", delegate() {
				WinForms.OpenFileDialog dialog = new WinForms.OpenFileDialog();
				dialog.Filter = "SilverMap Files (*.silvermap.xml)|*.silvermap.xml|Xml documents (*.xml)|*.xml|All files (*.*)|*.*";
				WinForms.DialogResult result = dialog.ShowDialog();

				if ( result == WinForms.DialogResult.OK ) {
					try {
						using ( StreamReader reader = new StreamReader( dialog.OpenFile() ) ) {
							model.Load( reader );
							reader.Close();
						}
					}
					catch ( Exception e ) {
						view.Alert( e.ToString() );
					}
				}
			} );

			page.AddTool( "details", "Details", delegate() {
				GeneDetails geneDetails = new GeneDetails( model, view );
				double w = page.Overlay.ActualWidth;
				double h = page.Overlay.ActualHeight;
				view.ShowWindow( geneDetails.Window, w * 0.25, h * 0.25, w * 0.5, h * 0.55 );
			} );

			page.AddTool( "status", "Status", delegate() {
				double w = page.Overlay.ActualWidth;
				double h = page.Overlay.ActualHeight;
				view.ShowWindow( Status.Instance.Window, w * 0.375, h * 0.375, w * 0.35, h * 0.35 );
			} );
		}
		
		public override void Init( IDictionary<string, string> initParams ) {
			Args.JumpTable["MapWebService"] = delegate( Model model, View view, string name, string value ) {
				if ( value != "null" ) {
					page.AddTool( "webLoad", "Load (web)", delegate () {
						Loader loader = new Loader( model, view );
						double w = page.Overlay.ActualWidth;
						double h = page.Overlay.ActualHeight;
						view.ShowWindow( loader.Dialog, w * 0.1, h * 0.1, w * 0.8, h * 0.8 );
					} );
				}
			};
						
			base.Init( initParams );
		}
	}
}
